<template>
	<!-- 收藏的族志 -->
	<view class="zuzhipage" >
		<view class="zuzhi_news_list" v-if="ZuzhiLits.length">
			<view @tap="todetaile(item.id)" class="zuzhi_news_item jus-b flex ali-c"  v-for="(item,index) in ZuzhiLits" :key="index">
				<view class="zuzhi_news_item_left  flexv flex">
					<view class="zuzhititle twoline">{{item.title}}</view>
					<view class="new_author_info flex ali-c">
						<image v-if="item.photo" class="author_txing" :src="photo_cdn+item.photo" mode=""></image>
						<view v-if="item.name" class="author_names">{{item.name}}</view>
						<view v-if="item.upload_name" class="author_names">{{item.upload_name}}</view>
						<view class="author_datetime">{{item.createtime}}</view>
						
						<image @tap.stop="cancelfun(item,index)" class="cancel_sc" :src="photo_cdn + 'zpupload/static/zupu/cancel_sc.png'" mode=""></image>
					</view>
				</view>
				<view class="zuzhi_news_item_right">
					<image class="news_imgs" :src="photo_cdn+item.image_url" mode=""></image>
				</view>
			</view>
		</view>
		<empty v-else></empty>
		
	</view>
</template>

<script>
	import {getCollectArticle,cancelCollectArticle } from "@/utils/api/zuzhi.js";
	import config from "@/utils/config.js";
	let {uploadFile,photo_cdn} = config.baseUrl;
	
	export default {
		data() {
			return {
				photo_cdn,
				statusBarHeight: 0, //通知栏高度
				page:0,
				isshowall:false,
				ZuzhiLits:[],
			}
		},
		onLoad() {
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight * 2;	
		},
		onShow(){
			this.ZuzhiLits = [];
			this.page = 0;
			this.isshowall = false;
			this.getCollectArticlefun();
		},
		onPullDownRefresh() {
			setTimeout(()=>{
				uni.stopPullDownRefresh(); //结束下拉刷新
			},3000)
		},
		onReachBottom() {
			if(!this.isshowall){
				this.getCollectArticlefun();
			}else{
				this.$api.msg('没有更多了~');
			}
		},
		methods: {
			todetaile(article_id){
				uni.navigateTo({
					url:`/pages/zupu/newsdetaile/newsdetaile?article_id=${article_id}`,
				})
			},
			//取消收藏
			async cancelfun(item,index){
				let res = {};
				res = await cancelCollectArticle({
					article_id:item.id,
				})
				this.$api.msg(res.msg);
				if(res.code==1){
					this.ZuzhiLits.splice(index,1);
				}
				
			},
			getCollectArticlefun(){
				this.page++;
				getCollectArticle({
					page:this.page,
				}).then((res)=>{
					if(res.code==1){
						this.ZuzhiLits = [...this.ZuzhiLits,...res.data.list];
						if(res.data.list.length==0){
							this.isshowall = true;
							if(this.page>1){
								this.$api.msg('没有更多了~');
							}
						}else{
							this.isshowall = true;
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "./collectzhuzhi.scss";
</style>
